package demo13.Practice01;


/**
 * 新的计数类观察者模式（区分之前的）
 * */
public class QuackCounterObserver  implements QuackableObserver{
	QuackableObserver duck;
	static int numberOfQuacks;
	
	
	
	public QuackableObserver getDuck() {
		return duck;
	}

	//构造函数传参
	public QuackCounterObserver(QuackableObserver duck) {
	  this.duck =duck;
	}

	@Override
	public void query() {
		duck.query();// 当调用query()时就将调用委托给 QuackableObserver
		numberOfQuacks++;//记录次数
		
	}

	@Override
	public void registerObserver(Observer observer) {
		// TODO Auto-generated method stub
		duck.registerObserver(observer);
	}

	@Override
	public void notifyObservers() {
		// TODO Auto-generated method stub
		duck.notifyObservers();
		
	}

	@Override
	public String toString() {
		return duck.toString();
	}
	
}
